/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
public:
    int findBottomLeftValue(TreeNode *root)
    {
        TreeNode *tree = root;
        queue<TreeNode *> q;
        q.push(tree);
        int bottomLeft = 0;
        while (!q.empty())
        {
            bottomLeft = q.front()->val;
            int layerSize = q.size();
            for (int i = 0; i < layerSize; ++i)
            {
                tree = q.front();
                q.pop();
                if (tree->left != nullptr)
                {
                    q.push(tree->left);
                }
                if (tree->right != nullptr)
                {
                    q.push(tree->right);
                }
            }
        }
        return bottomLeft;
    }
};